package com.admin.business.background.venusOaInsurance;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 增加业主保险
 * @create: 2023-11-03 14:11:25
 **/
@Service("venusOaInsuranceService")
@Slf4j
public class VenusOaInsuranceService{

    @Resource
    VenusOaInsuranceDao venusOaInsuranceDao;

    /**
     * 添加增加业主保险,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - org_id:企业id
     *                   - pro_id:项目id
     *                   - user_id:操作人
     *                   - claimee_type:被理赔人:1.业主:2.租户:3车辆:4外包单位:5内部员工:6其他
     *                   - ins_name:名称
     *                   - claims_type:理赔类型
     *                   - event_time:事件时间
     *                   - ins_money:保险金额
     *                   - tr_money:要求金额
     *                   - ins_cer:理赔原因
     *                   - taking_sides:承担方
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:是否删除：0、正常，1、已删除
     *                   - ry_name:姓名
     *                   - ry_tell:电话
     *                   - employee_user_id:内部员工id
     *                   - driving_id:车辆id
     *                   - driving_number:车辆车牌号
     *                   - driving_color:车辆颜色
     *                   - outsouring_id:外包单位id
     *                   - outsourcing_unit_company_name:外包单位名称
     *                   - room_id:房间id
     *                   - district:区号
     *                   - floor:楼号
     *                   - unit:单元
     *                   - house_number:门牌号
     *                   - type_side:类型端，1.pc 2.业主端
     * @return
     * @author Ht
     * @create: 2023-11-03 14:11:25
     */
    @OpenApi
    public Return addVenusOaInsurance(CDO cdoRequest) {
        venusOaInsuranceDao.addVenusOaInsurance(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新增加业主保险数据
     *
     * @param cdoRequest - id:主键
     *                   - org_id:企业id
     *                   - pro_id:项目id
     *                   - user_id:操作人
     *                   - claimee_type:被理赔人:1.业主:2.租户:3车辆:4外包单位:5内部员工:6其他
     *                   - ins_name:名称
     *                   - claims_type:理赔类型
     *                   - event_time:事件时间
     *                   - ins_money:保险金额
     *                   - tr_money:要求金额
     *                   - ins_cer:理赔原因
     *                   - taking_sides:承担方
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:是否删除：0、正常，1、已删除
     *                   - ry_name:姓名
     *                   - ry_tell:电话
     *                   - employee_user_id:内部员工id
     *                   - driving_id:车辆id
     *                   - driving_number:车辆车牌号
     *                   - driving_color:车辆颜色
     *                   - outsouring_id:外包单位id
     *                   - outsourcing_unit_company_name:外包单位名称
     *                   - room_id:房间id
     *                   - district:区号
     *                   - floor:楼号
     *                   - unit:单元
     *                   - house_number:门牌号
     *                   - type_side:类型端，1.pc 2.业主端
     * @return
     * @author Ht
     * @create: 2023-11-03 14:11:25
     */
    @OpenApi
    public Return updateVenusOaInsuranceById(CDO cdoRequest) {
        venusOaInsuranceDao.updateVenusOaInsuranceById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除增加业主保险数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-11-03 14:11:25
     */
    @OpenApi
    public Return deleteVenusOaInsuranceById(CDO cdoRequest){
        int count = venusOaInsuranceDao.deleteVenusOaInsuranceById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除增加业主保险数据
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-11-03 14:11:25
     */
    @OpenApi
    public Return deleteVenusOaInsurance(CDO cdoRequest) {
        int count = venusOaInsuranceDao.deleteVenusOaInsurance(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取增加业主保险数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-11-03 14:11:25
     */
    @OpenApi
    public Return getVenusOaInsuranceById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaInsuranceDao.getVenusOaInsuranceById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取增加业主保险数据列表
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-11-03 14:11:25
     */
    @OpenApi
    public Return getVenusOaInsuranceListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaInsuranceDao.getVenusOaInsuranceListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaInsuranceDao.getVenusOaInsuranceCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取增加业主保险数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-11-03 14:11:25
     */
    @OpenApi
    public Return getVenusOaInsuranceListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaInsuranceDao.getVenusOaInsuranceListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaInsuranceDao.getVenusOaInsuranceCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
